﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PPPP1
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string name = TextBox1.Text;
            string pwd = TextBox2.Text;
            string age = RadioButton1.Checked ? "0" : "1";
            string email = TextBox3.Text;
            string conn = "server=.;uid=sa;pwd=123456;database=Student";
            SqlConnection con = new SqlConnection(conn);
            string sql = "insert into StudentInfo (name,age,email,pwd) values(@name,@age,@email,@pwd)";
            SqlParameter[] pars=
                {
                new SqlParameter("@name",name),
                new SqlParameter("@pwd",pwd),
                new SqlParameter("@age",age),
                new SqlParameter("@email",email)
            };
            try
            {
                con.Open();
                SqlCommand com = new SqlCommand(sql, con);
                com.Parameters.AddRange(pars);
                int i = com.ExecuteNonQuery();
                if (i!=1)
                {
                    Literal1.Text = "注册成功，<a href='WebForm1.aspx'>去登录</a>";
                }
                else
                {
                    Literal1.Text = "注册失败!";
                }
            }
            catch (Exception ex)
            {

                throw new Exception(ex.Message);
            }
            finally
            {
                if (con!=null)
                {
                    con.Close();
                }
            }
        }
    }
}